var $ = getApp(),
  methods = require("../methods.js");
Page(Object.assign({}, methods, {
  data: {
    type: 'juli',
    longitude: '',
    latitude: '',
    detail: {},
    current: 0,
    isplay: 0,
    commentlist: [],
    showwx: false,
  },
  _onLoad: function () {
    var that = this
    var id = 0;
    console.log('detail003', that.options)
   
    if (that.options && that.options.id) {
      id = that.options.id
    }
    if (that.options && that.options.scene) {
      var scene = that.options.scene
      var scenes = scene.split('_');
      if (scenes[1]) {
        id = parseInt(scenes[1]);
      }
    }
    that.setData({
      id: id
    })
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        that.setData({
          longitude: longitude,
          latitude: latitude
        })
        that.getDataDetail();
      },
      fail: function () {
        that.getDataDetail();
      }
    })
  },
  tobuy: function (e) {
    console.log('点击购票')
    this.getinfo()
    //显示加载界面
    wx.showLoading({ // 显示加载中loading效果 
      title: "加载中",
      mask: true //开启蒙版遮罩
    });
    var id = this.data.detail.id;
    // $.goto('./buy?id=' + id);
    wx.navigateTo({
      url: '/diaoyu/pages/buy?id=' +id,
    })

    //隐藏加载界面
    wx.hideLoading();
  },
  previewImage(e) {
    console.log('3433', e)
    var currentUrl = e.currentTarget.dataset.src //获取当前点击图片链接
    wx.previewImage({
      current: currentUrl, //当前点击的预览图片链接
      urls: this.data.detail.pic, //需要预览的图片列表
    })
  },
  getinfo(){
    console.log('res000')
      $.get("/yuxun/getinfo",{},function(res){
      console.log('res111',res)
     if(res.data.nickname == '微信用户'){
     wx.showModal({
       title: '提示',
       content: '购票需先完善头像和名称信息',
       complete: (res) => {
         if (res.cancel) {
           
         }
     
         if (res.confirm) {
          $.goto('/pages/my/set')
         }
       }
     })
     }
    })
    console.log('res222')
  },
  getDataDetail: function () {
    var that = this;
    var id = that.data.id,
      longitude = that.data.longitude,
      latitude = that.data.latitude;
    $.post('yuxun/getDataDetail', {
      id: id,
      longitude: longitude,
      latitude: latitude
    }, function (res) {
      if (res.status == 0) {
        $.alert(res.msg);
        return;
      }
      var detail = res.detail;


      var pagecontent = JSON.parse(detail.content);
      var _bannerindex = [];
      for (var i in pagecontent) {
        _bannerindex[i] = 0;
      }

      that.setData({
        detail: detail,
        sysset: res.sysset,
        pagecontent: pagecontent,
      });

      wx.setNavigationBarTitle({
        title: ""
      });
    })
  },
  nav(e) {
    let that = this
    console.log('detail111', this.data.detail)
    let result = this.data.detail.zuobiao.split(',');
    console.log('009', result, result[0], result[1])
    wx.openLocation({
      latitude: Number(result[0]), //维度
      longitude: Number(result[1]), //经度
      name: this.data.detail.address, //目的地定位名称
      scale: 15, //缩放比例
      // address: "目的地"	//导航详细地址
    })
  },
  swiperChange: function (e) {
    var that = this;
    that.setData({
      current: e.detail.current
    })
  },
  collect: function (e) {
    var that = this;
    var id = that.data.detail.id;

    $.post('yuxun/collect', {
      id: id
    }, function (res) {
      if (res.status == 1) {
        // 取反当前项的点赞状态
        if (res.type == 1) {
          that.setData({
            [`detail.is_collect`]: 1
          })
        } else {
          that.setData({
            [`detail.is_collect`]: 0
          })
        }

      } else {
        $.error(res.msg);
        return false;
      }
    })
  },
  cancel: function (e) {
    var order_id = e.currentTarget.dataset.order_id;
    $.post('yuxun/cancelbaoming', {
      id: order_id
    }, function (res) {
      if (res.status == 1) {
        var detail = that.data.detail;
        detail.is_baoming = 0;
        that.setData({
          detail: detail
        });
      } else {
        $.error(res.msg);
      }
    })
  },
  showwx: function () {
    this.setData({
      showwx: true
    });
  },
  hidewx: function () {
    this.setData({
      showwx: false
    })
  }
}))